<?php

@include_once("../../commonFunctions.php");
@include_once("Classes/Store.php");

$table = $_GET['table'];
$table = strtolower($table);
if ($table == "computerissues") {
    return getUnresolvedComputerTable();
} else if ($table == "maintenance" || $table == "merchandising") {
    return getUnresolvedMaintMerchTable($table);
}

function getUnresolvedComputerTable() {
    $store = new Store($_SESSION['storeAbbrev']);
    $dealer = new Dealer($_SESSION['dealerCode']);
    $test = new TT('3');
    $compArr = array();
    $compArr = $test->fetchUnresolvedTT($store->storeAbbrev, 'computerissues');
    if (sizeof($compArr) != 0) { // No unresolved tickets
        echo "<table class=\"maintable\"";
        echo "<tr>
        <td class=\"tableheader\">TT ID</td>
        <td class=\"tableheader\">Submitted By</td>
        <td class=\"tableheader\">Assigned To</td>
        <td class=\"tableheader\">Type</td>
        <td class=\"tableheader\">Time Submitted</td>
        <td class=\"tableheader\">Time To Resolve</td>
        <td class=\"tableheader\">Description</td>
        <td class=\"tableheader\">PC</td>
        <td class=\"tableheader\">Status</td>
    </tr>";
        for ($i = 0; $i < sizeof($compArr); $i++) {
            $test = $compArr[$i];
            $assignedDealer = new Dealer($test->assignedTo);
            echo "<tr>";
            echo "<td><a href=showTickets_history.php?ttid=" . $test->id . ">" . $test->id . "</a></td>";
            echo "<td>" . $test->submittedByName . "</td>";
            echo "<td>" . $assignedDealer->firstName . ' ' . $assignedDealer->lastName . "</td>";
            echo "<td>" . $test->type . "</td>";
            echo "<td>" . $test->dateTimeSubmitted . "</td>";
            echo "<td>" . $test->dateTimeFinished . "</td>";
            echo "<td>" . $test->description . "</td>";
            echo "<td>" . $test->specialID . "</td>";
            echo "<td>" . $test->currentStatus . "</td>";
            echo "</tr>";
        }

        echo "</table>";
    } else {
        echo '<p class="issueline">No Unresolved Computer Issues</p>';
    }
}

function getUnresolvedMaintMerchTable($table) {
    $store = new Store($_SESSION['storeAbbrev']);
    $dealer = new Dealer($_SESSION['dealerCode']);
    $test = new TT('3');
    $compArr = array();
    $compArr = $test->fetchUnresolvedTT($store->storeAbbrev, $table);
    if (sizeof($compArr) != 0) { // No unresolved tickets
        echo "<table class=\"maintable\"";
        echo "<tr>
        <td class=\"tableheader\">TT ID</td>
        <td class=\"tableheader\">Submitted By</td>
        <td class=\"tableheader\">Assigned To</td>
        <td class=\"tableheader\">Type</td>
        <td class=\"tableheader\">Time Submitted</td>
        <td class=\"tableheader\">Time To Resolve</td>
        <td class=\"tableheader\">Description</td>
        <td class=\"tableheader\">Status</td>
    </tr>";
        for ($i = 0; $i < sizeof($compArr); $i++) {
            $test = $compArr[$i];
            $assignedDealer = new Dealer($test->assignedTo);
            echo "<tr>";
            echo "<td><a href=showTickets.php?ttid1=" . $test->id . ">" . $test->id . "</a></td>";
            echo "<td>" . $test->submittedBy . "</td>";
            echo "<td>" . $assignedDealer->firstName . ' ' . $assignedDealer->lastName . "</td>";
            echo "<td>" . $test->type . "</td>";
            echo "<td>" . $test->dateTimeSubmitted . "</td>";
            echo "<td>" . $test->dateTimeFinished . "</td>";
            echo "<td>" . $test->description . "</td>";
            echo "<td>" . $test->currentStatus . "</td>";
            echo "</tr>";
        }

        echo "</table>";
    } else {
        echo '<p class="issueline">No Unresolved ' . $table . ' Issues</p>';
    }
}

?>
